#!/bin/bash

# https://nodejs.org/zh-cn/download/

soft_dir=/opt/softs
version=v12.0.0
install_dir=/usr/local

yum install -y epel-release wget

cd ${soft_dir}
[ -f node-${version}-linux-x64.tar.xz ] || wget https://nodejs.org/dist/${version}/node-${version}-linux-x64.tar.xz
[ -f node-${version}-linux-x64.tar.xz ] && xz -d node-${version}-linux-x64.tar.xz

[ -d ${install_dir}/node-${version}-linux-x64 ] && rm -rf ${install_dir}/node-${version}-linux-x64
[ -d ${install_dir}/node-${version} ] && rm -rf ${install_dir}/node-${version}
tar -xvf node-${version}-linux-x64.tar -C ${install_dir}
mv ${install_dir}/node-${version}-linux-x64 ${install_dir}/node-${version}

[ -f ${install_dir}/node-${version}/bin/npm ] || exit 1
[ -f ${install_dir}/node-${version}/bin/node ] || exit 1

[ -L /usr/bin/npm ] && rm -f /usr/bin/npm
[ -L /usr/bin/node ] && rm -f /usr/bin/node

ln -s ${install_dir}/node-${version}/bin/npm /usr/bin/npm
ln -s ${install_dir}/node-${version}/bin/node /usr/bin/node

node --version
npm --version

# 一定要设置国内的，你想龟速可以不设置
npm config set registry https://registry.npm.taobao.org/
npm config get registry